
//
//  PhotoBrowserViewCell.swift
//  SwiftPhophotoBrowser
//
//  Created by xmg on 16/8/20.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit
import SDWebImage
class PhotoBrowserViewCell: UICollectionViewCell {
    
    /** 加载图片控制器 */
    lazy var imageView : UIImageView = UIImageView()
    
    /** 加载模型属性 */
    var shops : CommodityDisplay? {
        didSet{
            /** 是否有值 */
            guard let shops = shops else{return}
            
            /** 获取小图片 */
            var smallImage = SDWebImageManager.sharedManager().imageCache.imageFromDiskCacheForKey(shops.q_pic_url)
            /** 不为空,设置占位图片 */
            if smallImage == nil {
            smallImage = UIImage(named: "empty_picture")
            }
            /** 根据计算放大之后的frame */
            imageView.frame = calculatePictureSizeWithImage(smallImage)
            /** 获取url */
            let url = NSURL(string: shops.z_pic_url)
            imageView.sd_setImageWithURL(url) { (image:UIImage!, error :NSError!, type:SDImageCacheType, url:NSURL!) -> Void in
                /** 设置大图 */
                self.imageView.frame = calculatePictureSizeWithImage(image)
            }
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        /** 添加图片 */
        contentView.addSubview(imageView)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
